package cn.hp.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component //交给spring管理
@Aspect //切面类
public class MyAspect {

	//声明一个切入点
	@Pointcut(value="execution(* cn.hp.domain.Man.eat())")
	public void pc() {
		
	}
	
	/*//前置通知，切入到pc的切入点
	@Before(value="pc()")
	public void beforePc() {
		before();
	}
	
	//后置通知
	@After(value="pc()")
	public void afterPc() {
		after();
	}*/
	
	//环绕通知
	@Around(value="pc()")
	public void aroundPc(ProceedingJoinPoint point) throws Throwable {
		before();
		point.proceed();
		after();
	}
	
	//通知，增强的方法
	public void before() {
		System.out.println("饭前搞一杯");
	}
	
	public void after() {
		System.out.println("饭后搞一杯");
	}
	
}
